<template>
    <h2>房号修改</h2>
    <table>
        <tr>
            <td>房号</td>
            <td>
                <input type="text" v-model="poien.nname">
            </td>
        </tr>
        <tr>
            <td>房间类型</td>
            <td>
                <select v-model="poien.rid">
                    <option value="">请选择</option>
                    <option :value="pi.roomID" v-for="pi in fxlist">{{ pi.rname }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>房态</td>
            <td>
                <select v-model="poien.stateid">
                    <option value="">请选择</option>
                    <option :value="iopw.sid" v-for="iopw in ftlist">{{ iopw.statename }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>备注</td>
            <td>
                <textarea cols="30" rows="3" v-model="poien.desc"></textarea>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="修改" @click="ownnkws">
            </td>
        </tr>
    </table>
  </template>
  
  <script setup lang="ts">
  import {onMounted, reactive, toRefs} from 'vue'
  import {useRouter,useRoute} from 'vue-router'
  import axios from 'axios'
  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    poien:[],
    fxlist:[],
    ftlist:[]
  })
  let {poien,ftlist,fxlist} =toRefs(data)

  onMounted(()=>{
    gettype()
    getstates()
    fannumlist()
  })

  const gettype:any=()=>{
    axios({
        url:'/api/Room/Bindtype',
        method:'get'
    })
    .then(res=>{
        fxlist.value=res.data.data;
    })
  }

  const getstates:any=()=>{
    axios({
        url:'/api/Room/Bindstates',
        method:'get'
    })
    .then(res=>{
        ftlist.value=res.data.data;
    })
  }

  //反填
  const fannumlist=()=>{
    let obj={
        nid:route.query.nid
    }
    axios({
        url:'/api/Room/Selectid',
        method:'get',
        params:obj
    })
    .then(res=>{
        poien.value=res.data.data;
    })
  }

  const ownnkws=()=>{
    let obj={
        "nid": route.query.nid,
        "nname": poien.value.nname,
  "rid": poien.value.rid,
  "stateid": poien.value.stateid,
  "desc": poien.value.desc,
  "nstates": 1,
  "isDelete": false
    }
    axios({
        url:'/api/Room/Updatenum',
        method:'post',
        data:obj
    })
    .then(res=>{
        if(res.data.data==1){
            alert("修改房号信息成功")
            router.push('shownum')
        }else{
            alert("修改房号信息失败")
        }
    })
  }

  </script>
  
  <style scoped>
  
  </style>
  